$(document).ready(function(){

    $.ajax({
        type: "post",
        url:ctx + "school/grade/getGradeList",
        async:false,
        dataType: "json",
        success: function(res){
            if (null != res) {
                var html = '<option value="">请选择</option>';
                var selectedId = $("#gradeId").attr('grade-id');
                Object.keys(res).forEach(function(key){

                    if(selectedId == res[key].id){
                        html += '<option selected = "selected"value="' + res[key].id + '" data-tokens="'+ res[key].gradeName+'">' + res[key].gradeName+ '</option>';
                    }else{
                        html += '<option  value="' + res[key].id + '" data-tokens="'+ res[key].gradeName+'">' + res[key].gradeName+ '</option>';
                    }


                });
                $("#gradeId").html(html);
                //必须加，刷新select
                $("#gradeId").selectpicker('refresh');
            }
        }
    });


    //绑定bootstrap-select事件
    $.ajax({
        type: "post",
        url:ctx + "school/classInfo/getClassList",
        async:false,
        dataType: "json",
        success: function(res){
            if (null != res) {
                var html = '<option value="">请选择</option>';
                var selectedId = $("#classId").attr("class-id");
                Object.keys(res).forEach(function(key){
                  if(selectedId == res[key].id){
                        html += '<option selected = "selected" value="' + res[key].id + '" data-tokens="'+ res[key].className+'">' + res[key].className+ '</option>';
                  }else{
                        html += '<option value="' + res[key].id + '" data-tokens="'+ res[key].className+'">' + res[key].className+ '</option>';
                  }

                });
                $("#classId").html(html);
                //必须加，刷新select
                $("#classId").selectpicker('refresh');
            }
        }
    });
});
